package lif.dubbo.provider;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BootStrap {
	private static final BootStrap instance = new BootStrap();
	private static AbstractApplicationContext context;

	/**
	 * 启动容器
	 * 
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		start(); 
	}

	public static void start() throws InterruptedException {
		context = new ClassPathXmlApplicationContext(new String[] { "dubbo-demo-provider.xml" });
		synchronized (instance) {
			instance.wait();
		}
	}

	public static void restart() {
		context.refresh();
	}

	public static void stop() {
		context.destroy();
		synchronized (instance) {
			instance.notify();
		}
	}

	public static boolean isRunning() {
		if (context == null)
			return false;
		return context.isRunning();
	}
}
